// 这个reducer只负责管理收藏列表
function collReducer(state = [], action = { type: '', payload: null }) {
    let newstate = JSON.parse(JSON.stringify(state));

    if (action.type == 'ADD') {
        let index = newstate.findIndex((element) => {
            return element.id == action.payload.id
        })
        if (index == -1) {
            newstate.push(action.payload)
        }
        return newstate;
    } else if (action.type == 'DELETE') {
        let index = newstate.findIndex((element) => {
            return element.id == action.payload
        })
        console.log('DELETE中的index', index)
        if (index != -1) {
            newstate.splice(index, 1)
            console.log('删除中的newstate', newstate)
        }

        return newstate;
    } else if (action.type == 'EDIT') {
        newstate = action.payload
        return newstate;
    } else {
        return state
    }


}
//无名导出
export default collReducer